package excel

import (
	"fmt"
	"github.com/tealeg/xlsx"
	"time"
)

func ImportExcel(path string) (res interface{}, err error) {
	file, err := xlsx.OpenFile(path)
	if err != nil {
		return nil, err
	}
	returnData := make([]interface{}, 0, len(file.Sheets)) //创建一个空的切片
	channel := make(chan string, 0)
	go func() {
		for {
			select {
			case v, _ := <-channel:
				time.Sleep(time.Duration(2) * time.Second)
				fmt.Println(v)
			}
		}

	}()

	for _, v := range file.Sheets {
		if v.MaxRow == 0 {
			continue
		}
		rowData := make([]interface{}, 0, v.MaxRow)
		for _, rowValue := range v.Rows {
			colData := make([]interface{}, 0, v.MaxCol)
			for _, colValue := range rowValue.Cells {
				colData = append(colData, colValue.String())
				go func() {
					channel <- colValue.String()
				}()
			}
			rowData = append(rowData, colData)
		}
		returnData = append(returnData, rowData)
	}
	return returnData, nil
}
